/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-10-13 16:30:54
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-03-29 11:22:48
 * @FilePath: \code\cwp-front\pc-collaboration\src\store\modules\url-params.js
 * @Description: 模板相关数据
 */
import { defineStore } from 'pinia';
import pinia from '@/store';
export const useUrlParamsStore = defineStore('urlParams', {
    state: () => ({
        isInit: false,
        urlParams: {},
    }),
    actions: {
        /**
         * @description: 设置iframe的url
         * @param {string}iframe的url
         */
        initUrlParams() {
            let arr = window.location.search.slice(1).split('&');
            let params = {};
            arr.forEach((aParams) => {
                var aParam = aParams.split('=');
                params[aParam[0]] = aParam[1];
            });

            this.urlParams = params;
        },

        getUrlParams() {
            if (!this.isInit) this.initUrlParams();
            this.isInit = true;

            return this.urlParams;
        },
    },
});

//在vue上下文之外使用
export function useUrlParamsWithOut() {
    return useUrlParamsStore(pinia);
}
